package com.fjh.config;

import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import reactor.core.publisher.Mono;


/**
 * 限流的配置
 */
@Configuration
public class RequestLimitConfig {
    /**
     * ip限流
     */
    @Bean
    @Primary
    public KeyResolver ipKeyResolver(){
        return exchange -> Mono.just(exchange.getRequest().getHeaders().getHost().getHostString());
    }
    /**
     * api限流
     */
    @Bean
    public KeyResolver apiKeyResolver(){
        return exchange -> Mono.just(exchange.getRequest().getURI().getPath());
    }
}
